package com.mike.mybatis;


import java.util.HashMap;
import java.util.Map;

public class DBSql {
    private static final Map<Class, SqlBaseDao> daoMap = new HashMap();

    public DBSql() {
    }

    public static void register(SqlBaseDao SqlBaseDao) {
        Class cls = ClassUtils.genericType(0, SqlBaseDao.getClass());
        SqlBaseDao dao = (SqlBaseDao)daoMap.get(cls);
        if (dao != null) {
            throw new RuntimeException("dao double register");
        } else {
            daoMap.put(cls, SqlBaseDao);
        }
    }

    public static SqlBaseDao build(Class cls) {
        SqlBaseDao dao = (SqlBaseDao)daoMap.get(cls);
        if (dao == null) {
            throw new RuntimeException("dao not found");
        } else {
            return dao;
        }
    }
}
